﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace Rites.GameObjects
{
    [Serializable]
    public class Map
    {
        public Location[,] Locations { get; set; }

        //public string Serialize()
        //{
        //    XmlSerializer serializer = new XmlSerializer(typeof(Map));
        //    TextWriter stringWriter = new StringWriter();
        //    serializer.Serialize(stringWriter, this);
        //    return stringWriter.ToString();
        //}

        //public Map Deserialize(string xml)
        //{
        //    XmlSerializer serializer = new XmlSerializer(typeof(Map));
        //    TextReader stringRdr = new StringReader(xml);
        //    return (Map)serializer.Deserialize(stringRdr);
        //}

        public Map()
        {
        }

        public bool IsValid(int testX, int testY)
        {
            if (testX < 0 || testX > Width)
                return false;

            if (testY < 0 || testY > Height)
                return false;

            return true;
        }

        public int Width { get; set; }
        public int Height { get; set; }

        public void CreateTestMap()
        {
            int x = Constants.VIEW_TILES_ACROSS * 2;
            int y = Constants.VIEW_TILES_DOWN * 2;

            Locations = new Location[x,y];

            Width = x - 1;
            Height = y - 1;

            for (int xCount = 0; xCount < x; xCount++)
                for (int yCount = 0; yCount < y; yCount++)
                {
                    if (xCount == 0 || xCount == 7 || yCount == 7)
                        Locations[xCount,yCount] = new Location(eTerrainTypes.Pebbles, xCount, yCount);
                    else
                        Locations[xCount,yCount] = new Location(eTerrainTypes.Grass, xCount, yCount);
                }
        }
    }
}
